package com.example.gank.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.android.core.base.BaseActivity;
import com.example.gank.R;
import com.example.gank.adapter.PageAdapterWithFragment;
import com.example.gank.fragmet.AndroidGankFragment;
import com.example.gank.fragmet.WelfareFragment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BaseActivity {
    @BindView(R.id.tb_navi)
    TabLayout tbNavi;
    @BindView(R.id.vp_gank)
    ViewPager vpGank;
    private List<Fragment> fragments;
    private List<String> fragmentTitles;
    private PageAdapterWithFragment gankAdapter;


    @Override
    protected int getLayoutResource() {
        return R.layout.activity_main;
    }

    @Override
    protected void onInitView(Bundle bundle) {
        initFragments();
        gankAdapter = new PageAdapterWithFragment(getSupportFragmentManager(), fragments);
        gankAdapter.setmFragmentTitles(fragmentTitles);
        vpGank.setAdapter(gankAdapter);
        tbNavi.setupWithViewPager(vpGank);

    }

    private void initFragments() {
        fragmentTitles = new ArrayList<>();
        String[] stringArray = getResources().getStringArray(R.array.navi_title);
        Collections.addAll(fragmentTitles, stringArray);
        fragments = new ArrayList<>();
        fragments.add(AndroidGankFragment.newInstance());
        fragments.add(WelfareFragment.newInstance());
    }


}
